//
//  EstateFeeListViewController.h
//  daogouApp
//
//  Created by panquanReabam.com on 15/7/9.
//  Copyright (c) 2015年 jiezsoft.com. All rights reserved.

#import "FeeToPaViewController.h"

#import "HAODEsingleton.h"
#import "UIViewExt.h"
#import "RDVTabBarController.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "UIButton+WebCache.h"
#import "daogouview.h"
#import "NoticeDetailViewController.h"
#import "TheLoginViewController.h"
#import "MJRefresh.h"
#import "toPayCell.h"
#import "feeview.h"
#import "AppDelegate.h"
#import<CoreText/CoreText.h>
@interface FeeToPaViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate>


@end

@implementation FeeToPaViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    NSMutableArray*feeNo;
    NSMutableArray*feeDate;
    NSMutableArray*feeType;
    NSMutableArray*fid;
    NSMutableArray*totalMoney;
    NSMutableArray*couponMoney;
    NSMutableArray*payDate;
    NSMutableArray* payStatus;
    NSMutableArray* payStatusName;
    NSMutableArray* feeTypeName;
    NSMutableArray* unitName;
    NSMutableArray* unitPrice;
    NSMutableArray* quantity;
    NSMutableArray*  groupName;
    int pageNumber;
    daogouview*daogouviews;
    UILabel* noLabel;
    NSMutableArray *allComment;
    NSMutableArray *arr1;
    UIScrollView*scroll;
    feeview*feeviews;
    NSDictionary *jsonData;
     NSMutableArray *selectFeatureCodeArray;
     NSMutableArray *selectFeatureprice;
    NSMutableArray*couponId;
    NSMutableArray* useLimitAmt;
    NSMutableArray* title;
    NSMutableArray* price;

  
    UIButton* sxBtn;
    UIButton*jiantouBtn;
    UIButton*cardBtn;
    float lastContentOffset;
    UITextField*searchTextField;
    UITextField*jiuliaoTextFied;
    UIButton*daogouname;
    UIView*view1;
    daogouview*daogouView;
    UIScrollView*mainScroll;
    UIScrollView*MYmainScroll;
    UILabel*huiyuanname;
    UIButton *tureBtn;
    UILabel*dingdanhao1;
    UIButton *jiantouBtn1;
    UIButton *jiantouBtn2;
    UIButton *jiantouBtn3;
    UIButton *jiantouBtn4;
    UIButton *touBtn;
    UIButton *touBtn1;
    UIButton *touBtn2;
    UIButton *touBtn3;
    UIButton *touBtn4;
    UIButton *ToObtain;
    UIButton *btnDone;
    UIButton *jiagemingxi;
    BOOL saveAccount;
    BOOL saveAccount1;
    BOOL saveAccount2;
    BOOL saveAccount3;
    BOOL saveAccount4;
    UITextField*xianjinTextFied;
    NSMutableArray* arrrss;
    UIButton*hejibuyBtn1;
    NSString *payType;
}
@synthesize alt = alt;


#pragma mark - TextField delegate


-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden = NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
       UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    [Global showIndeterminateHud:@"获取数据，请稍后.." delay:30 view:self.view];
    [self add];
}
-(void)add{
    pageNumber=1;
    selectFeatureprice = [[NSMutableArray alloc] init];
selectFeatureCodeArray= [[NSMutableArray alloc] init];
    fid = [[NSMutableArray alloc] init];
    feeNo = [[NSMutableArray alloc] init];
    feeDate = [[NSMutableArray alloc] init];
    totalMoney= [[NSMutableArray alloc] init];
    couponMoney=[[NSMutableArray alloc] init];
    payDate = [[NSMutableArray alloc] init];
    payStatus = [[NSMutableArray alloc] init];
    payStatusName = [[NSMutableArray alloc] init];
    feeTypeName= [[NSMutableArray alloc] init];
    unitName = [[NSMutableArray alloc] init];
    unitPrice = [[NSMutableArray alloc] init];
    quantity= [[NSMutableArray alloc] init];
    feeType= [[NSMutableArray alloc] init];
    groupName= [[NSMutableArray alloc] init];
    useLimitAmt = [[NSMutableArray alloc] init];
    title= [[NSMutableArray alloc] init];
    price= [[NSMutableArray alloc] init];
    couponId= [[NSMutableArray alloc] init];
    _table.delegate=self;
    _table.dataSource=self;
    [self.view addSubview:_table];
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.title=@"缴交物业费";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    commdity=[HAODEsingleton shared];
    
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:commdity.orderId forKey:@"feeId"];
    
    NSLog(@"====%@",param);
    [HttpRequest requestData:@"Estate/Fee/ToPay" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"33333333====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                
                
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                
                 NSMutableArray* coupon=[[NSMutableArray alloc]init];
                
                coupon=[severDataDict.dataDict objectForKey:@"coupon"];
                jsonData=severDataDict.dataDict;
                

                
                NSString*GoldPrice=[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"totalMoney"]];
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setPositiveFormat:@"###,##0.00;"];
                NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
                
                for (int d = 0; d<1; d++) {
                    
                    
                    UIView *topView =[self addStoreTopView:CGRectMake(0, 210*d , ScreenWidth, 255) payStatus:[NSString stringWithFormat:@"%@",[jsonData valueForKey:@"payStatusName"]] totalMoney:[NSString stringWithFormat:@"%@",formattedNumberString] feeDate:[NSString stringWithFormat:@"%@",[jsonData valueForKey:@"feeDate"]] number:d];
 
                    
                    for (int i = 0; i < [[jsonData objectForKey:@"items"] count]; i++) {
                        
                        
                        feeviews = [[feeview alloc]initWithFrame:CGRectMake(0,90+25*i ,ScreenWidth, 15*i)];
                        feeviews.backgroundColor=[UIColor clearColor];
                        NSDictionary * dic = [[jsonData objectForKey:@"items"] objectAtIndex:i];//商品信息
                        
                        feeviews.feeType.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"feeTypeName"]];
                        feeviews.feeType.textColor=shenhuicolor;
                        double d;
                        double d1;
                        d= [[dic objectForKey:@"unitPrice"]doubleValue];
                        d1 = [[dic objectForKey:@"quantity"]doubleValue];
                        
                        feeviews.feeTypeName.text = [NSString stringWithFormat:@"%@ 元/%@ x %@ %@ =%.2f",[dic objectForKey:@"unitPrice"],[dic objectForKey:@"unitName"],[dic objectForKey:@"quantity"],[dic objectForKey:@"unitName"],  d*d1 ];
                        feeviews.feeTypeName.textColor=[UIColor blackColor];
                        
                        [topView addSubview:feeviews];
                        
                        
                    }
                    UIView*View=[[UIView alloc]initWithFrame:CGRectMake(0, 200, ScreenWidth, 10)];
                    View.backgroundColor=zuiqianhuicolor;
                    View.layer.borderColor = LineColor.CGColor;
                    [View.layer setBorderWidth:0.35];   //边
                    [topView addSubview:View];
                    
                    UILabel*youhui=[[UILabel alloc]initWithFrame:CGRectMake(15, View.bottom, 200, 45)];
                    youhui.text=@"优惠信息";
                    youhui.textColor=[UIColor blackColor];
                    youhui.font=[UIFont systemFontOfSize:15];
                    [topView addSubview:youhui];
                    UILabel*line35=[[UILabel alloc]initWithFrame:CGRectMake(0,255-0.35, ScreenWidth, 0.35)];
                    line35.backgroundColor=qianhuicolor;
                    [topView addSubview:line35];

                    
                    _table.tableHeaderView=topView;
                    
                    

                    for (NSDictionary* dicc in coupon )
                    {
                        [couponId addObject:[dicc valueForKey:@"couponId"]];
                        [title addObject:[dicc valueForKey:@"title"]];
                        [price addObject:[dicc valueForKey:@"price"]];
                        [useLimitAmt addObject:[dicc valueForKey:@"useLimitAmt"]];
                        
                    }
                    [_table reloadData];
                    
                    
               
                    
                    
                    UIView*zhifuView=[[UIView alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 360/2)];
                    zhifuView.backgroundColor=[UIColor whiteColor];
                    _table.tableFooterView=zhifuView;
                    UIView*View1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
                    View1.backgroundColor=zuiqianhuicolor;
                    [zhifuView addSubview:View1];
                    UILabel*line4=[[UILabel alloc]initWithFrame:CGRectMake(15, 45+10, ScreenWidth-30, 0.35)];
                    line4.backgroundColor=qianhuicolor;
                    [zhifuView addSubview:line4];
                    UILabel*line5=[[UILabel alloc]initWithFrame:CGRectMake(0,360/2-0.35+10, ScreenWidth, 0.35)];
                    line5.backgroundColor=qianhuicolor;
                    [zhifuView addSubview:line5];
                    UILabel*line6=[[UILabel alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 0.35)];
                    line6.backgroundColor=qianhuicolor;
                    [zhifuView addSubview:line6];
                    
                    
                    UILabel*shengyuzhifu=[[UILabel alloc]initWithFrame:CGRectMake(15, 10, 200, 45)];
                    shengyuzhifu.text=@"支付方式";
                    shengyuzhifu.textColor=[UIColor blackColor];
                    shengyuzhifu.font=[UIFont systemFontOfSize:15];
                    [zhifuView addSubview:shengyuzhifu];
                    
                    UIImageView *_xianview3 = [[UIImageView alloc]initWithFrame:CGRectMake(15,100, ScreenWidth-30, 0.5)];
                    _xianview3.image=[UIImage imageNamed:@"hengxian"];
                    [zhifuView addSubview:_xianview3];
                    UIImageView *_xianview4 = [[UIImageView alloc]initWithFrame:CGRectMake(15,290/2, ScreenWidth-30, 0.5)];
                    _xianview4.image=[UIImage imageNamed:@"hengxian"];
                    [zhifuView addSubview:_xianview4];

                    
                    jiantouBtn3 = [[UIButton alloc]init];
                    jiantouBtn3.frame = CGRectMake(15, 62, 30, 30);
                    [jiantouBtn3 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
                    [jiantouBtn3 addTarget:self action:@selector(chooseBtn3:) forControlEvents:UIControlEventTouchUpInside];
                    [zhifuView addSubview:jiantouBtn3];
                    touBtn3 = [[UIButton alloc]init];
                    touBtn3.frame = CGRectMake(ScreenWidth*100/750,62,30,30);
                    [touBtn3 setImage:[UIImage imageNamed:@"yinlian"] forState:UIControlStateNormal];
                    [touBtn3 addTarget:self action:@selector(chooseBtn3:) forControlEvents:UIControlEventTouchUpInside];
                    [zhifuView addSubview:touBtn3];
                    cardBtn = [[UIButton alloc]init];
                    cardBtn.frame = CGRectMake(touBtn3.right+10,55, ScreenWidth*100/750,45);
                    cardBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                    [cardBtn setTitle:@"银联" forState:UIControlStateNormal];
                    cardBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
                    [cardBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [cardBtn addTarget:self action:@selector(chooseBtn3:) forControlEvents:UIControlEventTouchUpInside];
                    [zhifuView addSubview:cardBtn];
               
                  
                    
                    jiantouBtn4 = [[UIButton alloc]init];
                    jiantouBtn4.frame = CGRectMake(15, 108, 30, 30);
                    [jiantouBtn4 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
                    [jiantouBtn4 addTarget:self action:@selector(chooseBtn4:) forControlEvents:UIControlEventTouchUpInside];
                    [zhifuView addSubview:jiantouBtn4];
                    touBtn4 = [[UIButton alloc]init];
                    touBtn4.frame = CGRectMake(ScreenWidth*100/750,195/2+10,30,30);
                    [touBtn4 setImage:[UIImage imageNamed:@"zhifubaosss"] forState:UIControlStateNormal];
                    [touBtn4 addTarget:self action:@selector(chooseBtn4:) forControlEvents:UIControlEventTouchUpInside];
                    [zhifuView addSubview:touBtn4];
                    cardBtn = [[UIButton alloc]init];
                    cardBtn.frame = CGRectMake(touBtn4.right+10,100, 150*ScreenWidth/750,45);
                    cardBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                    [cardBtn setTitle:@"支付宝" forState:UIControlStateNormal];
                    cardBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
                    [cardBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [cardBtn addTarget:self action:@selector(chooseBtn4:) forControlEvents:UIControlEventTouchUpInside];
                    [zhifuView addSubview:cardBtn];
                    
                    
                    
                    jiantouBtn2 = [[UIButton alloc]init];
                    jiantouBtn2.frame = CGRectMake(15, 286/2+10, 30, 30);
                    [jiantouBtn2 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
                    [jiantouBtn2 addTarget:self action:@selector(chooseBtn2:) forControlEvents:UIControlEventTouchUpInside];
                    [zhifuView addSubview:jiantouBtn2];
                    touBtn4 = [[UIButton alloc]init];
                    touBtn4.frame = CGRectMake(ScreenWidth*100/750,285/2+10,30,30);
                    [touBtn4 setImage:[UIImage imageNamed:@"weixinsss"] forState:UIControlStateNormal];
                    [touBtn4 addTarget:self action:@selector(chooseBtn2:) forControlEvents:UIControlEventTouchUpInside];
                    [zhifuView addSubview:touBtn4];
                    cardBtn = [[UIButton alloc]init];
                    cardBtn.frame = CGRectMake(touBtn4.right+10,270/2+10, 100*ScreenWidth/750,45);
                    cardBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
                    [cardBtn setTitle:@"微信" forState:UIControlStateNormal];
                    cardBtn.titleLabel.font = [UIFont systemFontOfSize: 15.0];
                    [cardBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [cardBtn addTarget:self action:@selector(chooseBtn2:) forControlEvents:UIControlEventTouchUpInside];
                    [zhifuView addSubview:cardBtn];
                    
                    [scroll setContentSize:CGSizeMake(ScreenWidth, cardBtn.bottom+150)];
                    
                    
                   
                    
                    hejibuyBtn1=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth*430/750, 45)];
                    [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"实付金额 ¥ %@",GoldPrice] forState:UIControlStateNormal];
                    hejibuyBtn1.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
                    [hejibuyBtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    hejibuyBtn1.alpha=0.8;
                    
                    
                        [self.view addSubview:hejibuyBtn1];
                        
                        UIButton*buyBtn2=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*430/750, ScreenHeight-45, ScreenWidth*320/750, 45)];
                        [buyBtn2 setTitle:@"去支付" forState:UIControlStateNormal];
                        buyBtn2.backgroundColor=luseColor;
                        [buyBtn2 addTarget:self action:@selector(queren:) forControlEvents:UIControlEventTouchUpInside];
                        
                        [buyBtn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                        [self.view addSubview:buyBtn2];
             
                    
                }
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
                
                
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHud:requestResultStr view:self.view];
                    
                    TheLoginViewController*vc1=[[TheLoginViewController alloc] init];
                    
                    [self.navigationController pushViewController:vc1 animated:YES];
                    
                    
                    
                }
            }
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
}


-(void)queren:(UIButton*)sender
{
    
    if ([payType length] <1)
    {
        [self showAlertMessage:@"请选择支付方式"];
    }
    else{
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"tokenId"];
        if (Token ==nil) {
            Token=@"dd";
        }
        
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setValue:Token forKey:@"tokenId"];
        [params setValue:commdity.orderId forKey:@"feeId"];
//        [params setValue:payType forKey:@"payType"];
        
        NSRange range={7,hejibuyBtn1.titleLabel.text.length-7};
        NSString* string =[hejibuyBtn1.titleLabel.text substringWithRange:range];

       
        [params setValue:[NSString stringWithFormat:@"%.2f",  string.doubleValue] forKey:@"payAmount"];
        [params setValue:selectFeatureCodeArray forKey:@"couponIds"];
        
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
        
           NSLog(@"33333333====%@",params);
        [HttpRequest requestData:@"/Estate/Fee/AliPay" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                
                NSLog(@"33333333====%@",severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                 
                    
                    if ([payType isEqualToString:@"A"]) {
                        NSString *appScheme = @"zhi024fe293a9460a4";
                        
                        
                        NSString *orderInfoStr=[severDataDict.dataDict objectForKey:@"signInfo"];
                        NSLog(@"====%@",orderInfoStr);
                        
                        
                        
                        [[AlipaySDK defaultService] payOrder:orderInfoStr fromScheme:appScheme callback:^(NSDictionary *resultDic) {
                            NSLog(@"resultALIIIII=%@",resultDic);
                            
                            
                        }];

                    }
                
                    
                
                
                
                }else{
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    // [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
                
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
            
        }];
        
    }
    
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [couponId count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    toPayCell* cell = (toPayCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"toPayCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.saveAccount=YES;
    


        NSString*GoldPrice=[NSString stringWithFormat:@"%@",[price objectAtIndex:indexPath.row]];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    
    cell.title.text =[NSString stringWithFormat:@"%@ ¥ %@（满%@可使用）",  [title objectAtIndex:indexPath.row],formattedNumberString,[useLimitAmt objectAtIndex:indexPath.row]];
    cell.title.font=[UIFont systemFontOfSize:15];
    cell.title.textColor=shenhuicolor;
    NSString*cont=[title objectAtIndex:indexPath.row];
     NSString*pricecont=formattedNumberString;
    
    NSMutableAttributedString *AttributedStr2 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ ¥ %@（满%@可使用）",  [title objectAtIndex:indexPath.row],formattedNumberString,[useLimitAmt objectAtIndex:indexPath.row]]];
    
    [AttributedStr2 addAttribute:NSFontAttributeName
     
                           value:[UIFont systemFontOfSize:15.0]
     
                           range:NSMakeRange(0, cont.length)];
    
    [AttributedStr2 addAttribute:NSForegroundColorAttributeName
     
                           value:[UIColor blackColor]
     
                           range:NSMakeRange(0, cont.length)];
    [AttributedStr2 addAttribute:NSFontAttributeName
     
                           value:[UIFont systemFontOfSize:15.0]
     
                           range:NSMakeRange(cont.length, pricecont.length+3)];
    
    [AttributedStr2 addAttribute:NSForegroundColorAttributeName
     
                           value:hongsecolor
     
                           range:NSMakeRange(cont.length, pricecont.length+3)];
    
    
    cell.title.attributedText = AttributedStr2;


    [cell.xuanzeBtn setUserInteractionEnabled:NO];
    if  ([selectFeatureCodeArray containsObject:[couponId objectAtIndex:indexPath.row]]){
        
        
        [cell.xuanzeBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
    
        cell.saveAccount=NO;
        
    }

    
    
    if (couponId.count !=indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 45-0.35, ScreenWidth-30, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    if (couponId.count ==indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 45-0.35, ScreenWidth, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  45;
}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    
    NSString * quan=[useLimitAmt objectAtIndex:indexPath.row];
     NSString * payStatusNames=[NSString stringWithFormat:@"%@",[jsonData valueForKey:@"totalMoney"]];
    if (payStatusNames .intValue < quan.intValue) {
        [self showAlertMessage:[NSString stringWithFormat:@"满%@才可以使用！" , quan]];
        
    }else{
    
    
    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
    toPayCell *sharecell=(toPayCell *)cell;
    sharecell.saveAccount=! sharecell.saveAccount;
    
    if (!sharecell.saveAccount) {
        [selectFeatureprice addObject:[price objectAtIndex:indexPath.row]];
        [selectFeatureCodeArray addObject:[couponId objectAtIndex:indexPath.row]];
        
        
        
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        toPayCell *sharecell=(toPayCell *)cell;
          [sharecell.xuanzeBtn setUserInteractionEnabled:NO];
        [sharecell.xuanzeBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
        
        double su;
        NSNumber *sum = [selectFeatureprice valueForKeyPath:@"@sum.floatValue"];
        

        
        double sum2;
        su=sum.doubleValue;
        sum2=payStatusNames.doubleValue;
        
        NSLog(@"---%.f",su);
        
        [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"实际金额 ¥ %.f",(sum2-su)] forState:UIControlStateNormal];
        
    }
    else{
        
        
        
        
        
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        toPayCell *sharecell=(toPayCell *)cell;
          [sharecell.xuanzeBtn setUserInteractionEnabled:NO];
        [sharecell.xuanzeBtn setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
       
        
        
        
        
        if (selectFeatureCodeArray.count>0) {
            
            for (int i=0; i<selectFeatureCodeArray.count; i++) {
                
                NSString *codeStr = [selectFeatureCodeArray objectAtIndex:i];
                if ([codeStr isEqualToString:[couponId objectAtIndex:indexPath.row]] ) {
                    
                    [selectFeatureCodeArray removeObjectAtIndex:i];//从指定索引移除
                    [selectFeatureprice removeObjectAtIndex:i];//从指定索引移除
                }
                
        
            
            }

            double su;
            NSNumber *sum = [selectFeatureprice valueForKeyPath:@"@sum.floatValue"];
         
            su=sum.doubleValue;
            double sum2;
            sum2=payStatusNames.doubleValue;
            
            
            
            [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"实际金额 ¥ %.f",sum2-su] forState:UIControlStateNormal];
            

            
            
        }
    }
       
}
    
    
    
    
    
}
-(void)chooseBtn:(id)sender
{
    [jiantouBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
    
    [jiantouBtn1 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
}
-(void)chooseBtn1:(id)sender
{
    [jiantouBtn1 setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
    
    [jiantouBtn setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
}
-(void)chooseBtn2:(id)sender
{
    [self showAlertMessage:@"未开通支付功能！"];
//    if (<#condition#>) {
//        <#statements#>
//    }
//    payType=@"W";
//    
//    [jiantouBtn2 setImage:[UIImage imageNamed:@"yuanquansss"] forState:UIControlStateNormal];
//
//    [jiantouBtn3 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
//    [jiantouBtn4 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
}

-(void)chooseBtn3:(id)sender
{
    
    payType=@"B";
    [jiantouBtn2 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
    
    [jiantouBtn3 setImage:[UIImage imageNamed:@"yuanquansss"] forState:UIControlStateNormal];
    [jiantouBtn4 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
    
}
-(void)chooseBtn4:(id)sender
{
    
    payType=@"A";
    [jiantouBtn2 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
    
    [jiantouBtn3 setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
    [jiantouBtn4 setImage:[UIImage imageNamed:@"yuanquansss"] forState:UIControlStateNormal];
}

- (UIView *)addStoreTopView:(CGRect)frame payStatus:(NSString *)payStatusss totalMoney:(NSString *)totalMoneys feeDate:(NSString *)feeDatess number:(NSInteger)number {
    
    
    UIView *viewTop= [[UIView alloc]initWithFrame:frame];
    viewTop.backgroundColor = [UIColor whiteColor];
    UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,60, ScreenWidth-30, 0.5)];
    _xianview.image=[UIImage imageNamed:@"hengxian"];
    [viewTop addSubview:_xianview];
    
    UIView*diview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
    diview.backgroundColor=zuiqianhuicolor;
    [viewTop addSubview:diview];
    UILabel *line911=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.35)];
    line911.backgroundColor=qianhuicolor;
    [diview addSubview:line911];
    UILabel *line91=[[UILabel alloc] initWithFrame:CGRectMake(0, 10, ScreenWidth, 0.35)];
    line91.backgroundColor=qianhuicolor;
    [diview addSubview:line91];
    
    UILabel*feeDates = [[UILabel alloc]init];
    feeDates. textColor=[UIColor blackColor];
    [feeDates setFrame:CGRectMake(20, 20, 140, 35)];
    feeDates .text=[NSString stringWithFormat:@"%@物业费", feeDatess];
    feeDates.font =[UIFont systemFontOfSize:16];
    [viewTop addSubview:feeDates];

    
    
    
    UILabel *hejiduoshao =[[UILabel alloc]init];
    hejiduoshao.textColor=[UIColor blackColor];
    [hejiduoshao setFrame:CGRectMake(ScreenWidth-200,20, 165, 30)];
    hejiduoshao.text= [NSString stringWithFormat:@"¥ %@" ,totalMoneys];
    hejiduoshao.font = [UIFont systemFontOfSize:16];
    hejiduoshao.textAlignment=NSTextAlignmentRight;
    [viewTop addSubview:hejiduoshao];
    
    UILabel *line1=[[UILabel alloc] initWithFrame:CGRectMake(0, 210-0.35, ScreenWidth, 0.35)];
    line1.backgroundColor=qianhuicolor;
    [viewTop addSubview:line1];
    
    
    
    
    return viewTop;
}

- (void)zhifu:(UIButton *)button {
    
    
    //    NSMutableArray *array = [NSMutableArray array];
    //    for (NSDictionary *dic in [[[[jsonData objectForKey:@"DataLine"] allValues] objectAtIndex:button.tag] allValues]) {
    //        [array addObject:[dic objectForKey:@"cart_id"]];
    //
    //    }
    //从数组合并元素到字符串- componentsJoinedByString:
    
    //    NSString *string1 = [array componentsJoinedByString:@","];
    
    NSLog(@"string:%@",[[[jsonData objectForKey:@"DataLine"] objectAtIndex:button.tag]objectForKey:@"fid"]);
//    FeeToPaViewController* store=[[FeeToPaViewController alloc]init];
//    
//    [self.navigationController pushViewController:store animated:YES];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定哦 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}



- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
@end
